﻿using System;
using System.Collections.Generic;
 
using System.Text;

namespace GGSharp.Packets
{
    public class UserListReplyPacket : HeaderPacket
    {
        protected byte _type;		/* rodzaj zapytania */
        protected string _reply;		/* treść, nie musi wystąpić */

        public UserListReplyPacket()
        {
            this.Length = 1;
            this.Type = PacketType.GG_USERLIST_REPLY;
        }

        public string Reply
        {
            get { return _reply; }
        }

        public UserListReplyType ReplyType
        {
            get { return TranslateReplyType(_type); }
            set { _type = (byte)value; }
        }

        public byte ReplyTypeRaw
        {
            get { return _type; }
            set { _type = value; }
        }

        protected UserListReplyType TranslateReplyType(byte type)
        {
            try
            {
                return (UserListReplyType)_type;
            }
            catch (Exception e)
            {
                return UserListReplyType.Unknown;
            }
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            this.ReadedLength = 1;

            _type = reader.ReadByte();
            if (ReplyType == UserListReplyType.GetReply || ReplyType == UserListReplyType.GetMoreReply)
            {
                _reply = ReadCP1250Text(reader.ReadBytes(this.Length - 1), 0, this.Length - 1);
                this.ReadedLength = this.Length;
            }
            else
                ReadToEnd((int)this.ReadedLength, reader);
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            throw new NotImplementedException();
        }
    }
}
